package com.platform.utils.push;

/**
 * Created by zhurusen on 2018/7/5
 */
public class UPush {
//    private static String appkey = "5aebf4068f4a9d30bf0000f6";
//    private static String appMasterSecret = "irgjokpscpybg87jmriaycliqljwkzom";
//    private static String timestamp = null;
    private static PushClient client = new PushClient();

    public static void push(String mobileType, String deviceToken, String title, String text) {
        try {

            if (deviceToken != null && !deviceToken.isEmpty()) {
                if (mobileType.equals("android")) {
                    sendAndroidUnicast(deviceToken, title, text);
                }
                if (mobileType.equals("ios")) {
                    sendIOSUnicast(deviceToken, title, text);
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static void sendAndroidUnicast(String deviceToken, String title, String text) throws Exception {
        AndroidUnicast unicast = new AndroidUnicast("5aebf4068f4a9d30bf0000f6", "irgjokpscpybg87jmriaycliqljwkzom");
        // TODO Set your device token
        unicast.setDeviceToken(deviceToken);
        //通知栏提示文字
        unicast.setTicker("来自掏心窝一条新消息");
        //通知标题
        unicast.setTitle(title);
        //通知文字描述
        unicast.setText(text);
        unicast.goCustomAfterOpen("查看");
        unicast.setDisplayType(AndroidNotification.DisplayType.NOTIFICATION);
        // TODO Set 'production_mode' to 'false' if it's a test device.
        // For how to register a test device, please see the developer doc.
        unicast.setProductionMode();
        // Set customized fields
//        unicast.setExtraField("test", "helloworld");
        client.send(unicast);
    }

    public static void sendIOSUnicast(String deviceToken, String title, String text) throws Exception {
        IOSUnicast unicast = new IOSUnicast("5b1dec81b27b0a46c60000d5", "5ijvyuuplm6byy51crdvydgxfz7h9iqh");
        // TODO Set your device token
        unicast.setDeviceToken(deviceToken);
        unicast.setAlert(title);
        unicast.setDescription(text);
        unicast.setBadge(0);
        unicast.setSound("default");
        // TODO set 'production_mode' to 'true' if your app is under production mode
        unicast.setTestMode();
        // Set customized fields
//        unicast.setCustomizedField("test", "helloworld");
        client.send(unicast);
    }

    public static void main(String[] args) {
        // TODO set your appkey and master secret here
//        UPush demo = new UPush("5aebf4068f4a9d30bf0000f6", "irgjokpscpybg87jmriaycliqljwkzom");
        try {
//            demo.sendAndroidUnicast();
            /* TODO these methods are all available, just fill in some fields and do the test
             * demo.sendAndroidUnicast();
             * demo.sendAndroidCustomizedcastFile();
             * demo.sendAndroidBroadcast();
             * demo.sendAndroidGroupcast();
             * demo.sendAndroidCustomizedcast();
             * demo.sendAndroidFilecast();
             *
             * demo.sendIOSBroadcast();
             * demo.sendIOSUnicast();
             * demo.sendIOSGroupcast();
             * demo.sendIOSCustomizedcast();
             * demo.sendIOSFilecast();
             */
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

}
